#ifndef	_SAMPLE_H
#define	_SAMPLE_H

#include	"public.h"

/*** define the query mode ***/
#define		SAMPLE_MODE_MAX			1
#define		SAMPLE_MODE_MIN			2
#define		SAMPLE_MODE_MAX_MIN		3
#define		SAMPLE_MODE_COMMON		4

// define the error no
#define		ERR_CURVE_QUERY_PRO		-1
#define		ERR_CURVE_NOT_DEFINE		-2
#define		ERR_CURVE_NO_TABLE		-3
#define		ERR_CURVE_NO_COLUMN		-4
#define		ERR_CURVE_WRONG_APP		-5
#define		ERR_CURVE_NO_INTERVAL		-6


// define the max limit number for sample_data
#define		MAX_SAMPLE_RECORD_NUMBER	1440

// Added by ZJH 00.05.05 for ChongQing 1s and 1m sample
//#define		ONE_SECOND_SAMPLE		100
//#define		ONE_MINUTE_SAMPLE		101	

// define the result_mean
#define		RESULT_NORMAL			0
#define		RESULT_NULL			1
#define		RESULT_NOMEAN			2

// define the constants (in menu_info) used for YX REGISTER information
#define		YX_OFF				0
#define		YX_ON				1

#define		YX_BW_ON			1
#define		YX_BW_OFF			2
#define		YX_ACC_OFF			3

#define		YX_LOCK_ON			1
#define		YX_LOCK_OFF			2
#define		YX_UNLOCK_ON			3
#define		YX_UNLOCK_OFF			4
#define		YX_OPER_ON			5
#define		YX_OPER_OFF			6

#define		YX_SOE_ACT			1
#define		YX_SOE_RET			2

#define		YX_STATUS_BW_ON			7
#define		YX_STATUS_BW_OFF		8
#define		YX_STATUS_ACC_OFF		10

#define		YX_STATUS_LOCK_ON		4
#define		YX_STATUS_LOCK_OFF		5
#define		YX_STATUS_NORMAL		0
#define		YX_STATUS_OPER			6

#define		YX_STATUS_SOE_ACT		11
#define		YX_STATUS_SOE_RET		12

	
	
/*** define the key_sample_info structure ***/
typedef struct _key_sample_info
{
	unsigned char	success;
	KEYID_TYPE	key_id;
	char		sample_table_name[MAX_TABLE_NAME_ENG_LEN];
	char		sample_column_name[MAX_COLUMN_NAME_ENG_LEN];
	char		sample_status_name[MAX_COLUMN_NAME_ENG_LEN];
	unsigned int	sample_interval;
}	KEY_SAMPLE_INFO;

/*** define the result set ***/
typedef struct _sample_result_2
{
	int		occur_time;
	unsigned char	is_null;
	unsigned char	yx_value;
	float		yc_value;
	unsigned char	status;
	double          dd_value;
}	SAMPLE_RESULT_2;

/*** define the sample result head ***/
typedef struct _sample_result_head
{
	short		no;
	int		cur_time;
	int		cur_no;
	int		time_number;
	SAMPLE_RESULT_2  *sample_result;
}	SAMPLE_RESULT_HEAD;

typedef	struct	_modify_value_info
{
	int		occur_time;
	unsigned char	modify_flag;
	unsigned char	value_null;
	unsigned char	yx_value;
	float		yc_value;
	unsigned char	status_null;
	unsigned char	status_value;
	double          dd_value;
}	MODIFY_VALUE_INFO;

typedef struct	_yx_register
{
	int		table_no;
	int		occur_time;
	short		milli_second;
	int		status;
	unsigned char	yx_value;
	unsigned char	yx_status;
}	YX_REGISTER;

typedef struct	_yx_register_head
{
	short		no;
	int		time_number;
	YX_REGISTER	*yx_register;
}	YX_REGISTER_HEAD;

/***define the structure used for modify ***/
typedef	struct	_modify_sample_info
{
	int			time_number;
	MODIFY_VALUE_INFO	*modify_value_info;
}	MODIFY_SAMPLE_INFO;



/*** define the prototype of function ***/
extern int query_sample_data (
	char			*buffer,
	char			buffer_order_type,
	char			**result_link_ptr,
	int			*result_link_length
);
extern int get_sample_info_from_key_id (
	short			app_type,
	unsigned char		is_yc,
	short			key_number,
	KEY_SAMPLE_INFO		**key_sample_info
);
extern int get_max_devideable_number (
	short			key_number,
	KEY_SAMPLE_INFO		*key_sample_info
);
extern int get_time_list (
	int 			start_time, 
	int 			end_time, 
	unsigned char 		sample_mode, 
	short 			key_number, 
	KEY_SAMPLE_INFO 	*key_sample_info, 
	int 			*time_number, 
	int 			**time_list
);
extern int get_single_time (
	char			*sql_statement, 
	int 			*tmp_number, 
	int 			**tmp_list
);
extern int modify_sample_data (
	char			*buffer,
	char			buffer_type_order,
	char			**result_ptr,
	int			*result_length
);

#endif
